#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#include "KApplication.h"


KApplication::KApplication()
{
	_CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_LEAK_CHECK_DF);

	m_MsgLoopFunc = MsgLoop;
}

KApplication::~KApplication()
{
	_CrtDumpMemoryLeaks();
}

void KApplication::Run()
{
	m_MsgLoopFunc();
}

void KApplication::SetMsgLoopFunc(MsgLoopFunc msgLoopFunc)
{
	if(msgLoopFunc)
		m_MsgLoopFunc = msgLoopFunc;
}

void KApplication::MsgLoop()
{
	MSG msg;
	ZeroMemory(&msg, sizeof(msg));

	while( GetMessage(&msg, NULL, NULL, NULL) )
	{
		::TranslateMessage(&msg);
		::DispatchMessage(&msg);
	}
}
